<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/operateTag" prefix="o"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String otype = (String)request.getAttribute("otype");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>商家信息管理</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<jsp:include page="/page/head.jsp"></jsp:include>
	<script type="text/javascript">
		var otype = "<%=otype%>"
		//页面打开加载
		$(document).ready(function(){
			var url = path+'/organization/list.do?type='+otype;
		    $('#mgrTable').datagrid({
       			height: 500,
		        pageSize: 20,//每页显示的记录条数，默认为10  
		        pageList: [10,15,20],//可以设置每页记录条数的列表
				nowrap: true,
        		border: true,  
				striped: true,
				collapsible: false,
				url:url,
				sortName: 'id',
				sortOrder: 'asc',
				remoteSort: false,
				idField:'id',
				columns:[[
	                {field:'ck',checkbox:true},
	                {field:'code',title:'商家编号',width:60,hidden:${otype=='1'?false:true}},
					{field:'name',title:'名称',width:100},
					{field:'legal',title:'法人代表',width:60},
					{field:'tel',title:'联系人手机',width:85},
					{field:'ascore',title:'返利积分',width:55},
					{field:'sscore',title:'剩余积分',width:55},
					{field:'areaName',title:'所属区域',width:65},
					{field:'id',title:'操作',width:170,hidden:${otype=='1'||otype=='2'?false:true},
						formatter:function(value,rec){
								return '<a href=\"javascript:void(0);\" onclick=\"operateRole('+value+')\">设置卡号</a>'
								+'|'+'<a href=\"javascript:void(0);\" onclick=\"operateRole('+value+')\">会员明细</a>'
								+'|'+'<a href=\"javascript:void(0);\" onclick=\"operateRole('+value+')\">商家广告</a>';
							}
					}
				]],
				pagination:true,
				rownumbers:true,
				toolbar:'#toolbar'
			});
			var p = $('#mgrTable').datagrid('getPager');
			$(p).pagination({   
		        beforePageText: '第',//页数文本框前显示的汉字  
		        afterPageText: '页    共  {pages} 页',
		        displayMsg: '当前显示  {from} - {to} 条记录   共  {total} 条记录'
		    });
			
		});
		
	/*	//设置卡号
		function operateRole(id){
			window.location = path+"/organization/organization-role.do?id="+id;
		}
		//会员明细
		function operateRole(id){
			window.location = path+"/organization/organization-role.do?id="+id;
		}
	*/	
		var url;
		
		//添加商家/机构
		function add(){
			if(otype=='1') {
				window.location = path+"/organization/init.do?otype="+otype+"&type=add";
			} else {
				window.location = path+"/organization/init.do?otype="+otype+"&type=add";
			}
			
		}
		
		//编辑商家/机构
		function edit(){
			var selected = $('#mgrTable').datagrid('getSelected');
			if(selected){
				window.location = path+"/organization/init.do?otype="+otype+"&type=edit&organizationId="+selected.id;
			}else{
				if(otype=='1') {
					alertBox("请选择需要编辑的商家！");
				} else if(otype=='2') {
					alertBox("请选择需要编辑的推广站！");
				} else if(otype=='3') {
					alertBox("请选择需要编辑的推广中心！");
				}else if(otype=='4') {
					alertBox("请选择需要编辑的运营中心！");
				}else {
					alertBox("请选择需要编辑的机构！");
				}
			}
		}
		
		//移除商家/机构
		function remove(){
			var rows = $('#mgrTable').datagrid('getSelections');
			
			if(rows && rows.length!=0){
				var ids = [];
				for(var i=0;i<rows.length;i++){
					ids.push(rows[i].id);
				}
				
				var submit = function (v, h, f) {
				    if (v == 'ok'){
				    	url = path +"/organization/delete.do?ids="+ids.join(',')+"&t="+new Date().getTime();
						$.ajax({
						  url: url,
						  success: function(data) {
							   if(data == "1")
							   {
									$('#mgrTable').datagrid('reload');
									$('#mgrTable').datagrid('clearSelections');
							   } else {
									alertBox("操作失败！");
							   }
						  }
						});
				    }    	
				    return true;
				};
				
				$.jBox.confirm("确定要删除吗？", "提示", submit);
				
			}else{
				if(otype=='1') {
					alertBox("请选择需要删除的商家！");
				} else if(otype=='2') {
					alertBox("请选择需要删除的推广站！");
				} else if(otype=='3') {
					alertBox("请选择需要删除的推广中心！");
				}else if(otype=='4') {
					alertBox("请选择需要删除的运营中心！");
				}else {
					alertBox("请选择需要删除的机构！");
				}
				
			}
		}
		
		//刷新
		function refresh(){
			$('#mgrTable').datagrid('reload');
		}
		//查询
		function search(){
			var name = $('#name').val();
			var code = $('#code').val();
			var tel = $('#tel').val();
			var parent = $('#parent').val();
			$('#mgrTable').datagrid('reload',{name:name,code:code,tel:tel,parent:parent});			
		}
		//清除
		function clean(){
			$('#name').attr('value','');
			$('#code').attr('value','');
			$('#tel').attr('value','');
			$('#parent').attr('value','');
		}
	</script>

  </head>
  
  <body>
    <div class="right">
		<h1>
		<b>
		${otype=='1'?'商家管理':otype=='2'?'推广站':otype=='3'?'推广中心':otype=='4'?'运营中心':'机构管理'}
		</b><span><img src="<%=basePath %>images/right_h1bg2.jpg" width="3" height="29" /></span></h1>
		<div class="ri_main">
			<div>
			  <table width="90%" border="0" cellspacing="0" cellpadding="4">
				  <tr>
				    <td style="vertical-align: middle;">
				    	<label>名称</label>
				    	<input class="easyui-validatebox" type="text" name="name" id="name"/>
				        <label>&nbsp;${otype=='1'?'编号':''}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
				    	${otype=='1'?'<input class="easyui-validatebox" type="text" name="code" id="code"/>':''}
				    </td>
				  </tr>
				  <tr>
				    <td style="vertical-align: middle;">
				    	<label>电话</label>
				    	<input class="easyui-validatebox" type="text" name="tel" id="tel"/>
				    	<label>&nbsp;${otype=='1'?'所属机构':''}</label>&nbsp;
				    	${otype=='1'?'<input class="easyui-validatebox" type="text" name="parent" id="parent"/>':''}
				    	<input type="button" onclick="search()" value="查询" />
				        &nbsp;<input type="button" onclick="clean()" value="清除" />
				    </td>
				  </tr>
			 </table>
			</div>
			<div id="toolbar">
				<a href="javascript:void(0);" onclick="add()" class="easyui-linkbutton" iconCls="icon-add">新增</a>
				<a href="javascript:void(0);" onclick="edit()" class="easyui-linkbutton" iconCls="icon-edit">编辑</a>
				<a href="javascript:void(0);" onclick="remove()" class="easyui-linkbutton" iconCls="icon-remove">删除</a>
				<a href="javascript:void(0);" onclick="refresh()" class="easyui-linkbutton" iconCls="icon-reload">刷新</a>
			</div>
		 	<table id="mgrTable">
		 		
		 	</table>  
		</div>
	</div>
  </body>
</html>
